<script>
    function Add_gallery_type() {
	window.location.href = "?modul=gallery&action=add_gallery_slide_home";
    }
</script>

<?php

function V_Gallery_Home($arrayData, $mode, $id) {
    $ulr = "?" . MODUL . "=gallery&" . ACTION . "=";
    if ($mode == "gallery_slide_home") {
	$strLabel = "Danh sách ảnh slide banner";
	$strLabel2 = "Thêm mới ảnh Slide Banner";
    } else if ($mode == "gallery_home") {
	$strLabel = "Danh sách ảnh đẹp trang chủ";
	$strLabel2 = "Thêm mới ảnh đẹp trang chủ";
    }
    ?>
    <h3><?= $strLabel ?></h3>
    <form name="frm" action="<?= $ulr . $mode ?>"  method="post" enctype="multipart/form-data">
    <!--<p style="float: right"><input type="button" value="Thêm mới" onclick="Add_gallery_type();" /></p><br/>-->
        <table width="100%" cellpadding="5" border="1">
    	<tr style="background-color: #99CCFF">
    	    <th width="15px">STT</th>
    	    <th width="500px">Ảnh</th>
    	    <th width="30px">Sửa</th>
    	    <th width="30px">Xóa</th>
    	    <th width="15px">STT</th>
    	    <th width="500px">Ảnh</th>
    	    <th width="30px">Sửa</th>
    	    <th width="30px">Xóa</th>
    	</tr>
	    <?
	    if (!empty($arrayData)) {
		$a = 0;
		$count = count($arrayData);
		$haft = ceil($count / 2);
		for ($i = 0; $i < $haft; $i++) {
		    $a++;
		    ?>
	    	<tr>
	    	    <td><?= $a ?></td>
	    	    <td><img width="200px" src="<?= DIR_IMG_SLIDE_GALLERY_HOME . $arrayData[$i]['url_pic'] ?>"/></td>
	    	    <td>
			    <? if ($id == $arrayData[$i]['id']) { ?>
				<input type="file" name="url_pic" id="url_pic"/>
				<br/>
				<br/>
				<input type="submit" name="Submit" value="Lưu"/>
				<input type="hidden" name="id" id="id" value="<?= $id ?>"/>
			    <? } else { ?>
				<a href="<?= $ulr . $mode . "&id=" . $arrayData[$i]['id'] ?>">Sửa</a>
			    <? } ?>
	    	    </td>
	    	    <td><a onclick="return confirm('Bạn có chắc chắn muốn xóa không?');" href="<?= $ulr . "Del_pic&id=" . $arrayData[$i]['id'] . "&flag=gallery_home" ?>">Xóa</a></td>
			<?
			$next = $haft + $i;
			if ($next < $count) {
			    $a++;
			    ?>
			    <td><?= $a ?></td>
			    <td><img width="200px" src="<?= DIR_IMG_SLIDE_GALLERY_HOME . $arrayData[$next]['url_pic'] ?>"/></td>
			    <td>
				<? if ($id == $arrayData[$next]['id']) { ?>
		    		<input type="file" name="url_pic" id="url_pic"/>
		    		<br/>
		    		<br/>
		    		<input type="submit" name="Submit" value="Lưu"/>
		    		<input type="hidden" name="id" id="id" value="<?= $id ?>"/>
				<? } else { ?>
		    		<a href="<?= $ulr . $mode . "&id=" . $arrayData[$next]['id'] ?>">Sửa</a>
				<? } ?>
			    </td>
			    <td><a onclick="return confirm('Bạn có chắc chắn muốn xóa không?');" href="<?= $ulr . "Del_pic&id=" . $arrayData[$next]['id'] . "&flag=gallery_home" ?>">Xóa</a></td>
			    <?
			}
		    }
		} else {
		    echo "<tr><td colspan='8'>Khong co anh</td></tr>";
		}
		?>
    	<tr>
    	    <th colspan="8"><?= $strLabel2 ?></th>
    	</tr>
    	<tr>
    	    <th colspan="8">
    		<input type="file" multiple="multiple" name="url_pic_up[]" id="url_pic_up"/><br/>
    		<input type="submit" name="upload_gallery_home" id="upload_gallery_home" value="Upload"/><br/>
    	    </th>
    	</tr>
        </table>
    </form>
    <?
}
?>
